home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cppfos.zip / FOSSIL.HPP < prev   
C/C++ Source or Header  |  1991-05-21  |  10KB  |  355 lines

  1. // Header //
  2. //
  3. // FOSSIL
  4. //
  5. // Contents -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  6. //
  7. //    A FOSSIL communications class
  8. //
  9. //    Copyright (C) 1991 by J.R.Louvau
  10. //    All rights reserved.
  11. //
  12. // License
  13. //
  14. //    This source code is freely available, copyrighted material.
  15. //    You are free to incorporate it into other software you are developing
  16. //    in original or modified form. You may also distribute it in any way
  17. //    you see fit, provided you follow these guidelines:
  18. //    1) The contents of the header (".hpp") and source (".cpp") remain
  19. //       in their original form.
  20. //    2) You don't make a profit.
  21. //    3) Charging for a package you have developed which incorporates
  22. //       these routines in BINARY (.obj, .exe, etc.) is fine, but you may
  23. //       NOT include this SOURCE CODE in any for-profit package.
  24. //
  25. // Warranties, Liabilities, etc. ad nauseum
  26. //
  27. //    None! It works on my compiler, hardware, modem, etc. If it works
  28. //    for you, great... if not, well, that's why you got the source code -
  29. //    so that YOU could fix it ;-) You can't get blood from a turnip,
  30. //    and I'm a turnip. Help save the environment: starve a lawyer.
  31. //
  32. // Description
  33. //
  34. //    A serial I/O interface library for use with a FOSSIL driver.
  35. //
  36. // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  37.  
  38. #ifndef __FOSSIL_HPP
  39. #define __FOSSIL_HPP
  40.  
  41. #if __STDC__
  42. #define _Cdecl
  43. #else
  44. #define _Cdecl cdecl
  45. #endif
  46.  
  47. // comment this out if you want pre-compiled headers
  48. // in Borland C++
  49.  
  50. #ifdef __BCPLUSPLUS__
  51. #pragma hdrstop
  52. #endif
  53.  
  54. // Interface Dependencies -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  55. //
  56. // End Interface Dependencies -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  57.  
  58. // Implementation Dependencies =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  59.  
  60. #include <stddef.h>
  61.  
  62. // End Implementation Dependencies =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  63.  
  64. struct FosInfo
  65. {
  66.    unsigned char maxfunc,  // Maximum function # supported
  67.                  revision; // FOSSIL revision level
  68. };
  69.  
  70. struct TimInfo
  71. {
  72.    unsigned char intnum,     // timer interrupt NUMBER
  73.                  ticpersec;  // approx. ticks per second
  74.    unsigned int  mspertic;   // approx. milliseconds per tick
  75. };
  76.  
  77. struct FosData
  78. {
  79.      unsigned int  fdsize;                // Structure size
  80.      unsigned char specver;                // FOSSIL spec version
  81.      unsigned char drvlvl;                // Driver rev level
  82.      unsigned char far *drvid;            // Pointer to ASCII ID
  83.      unsigned int  rxsize;                // Input buffer size
  84.      unsigned int  rxavail;                // Bytes avail (input)
  85.      unsigned int  txsize;                // Output buffer size
  86.      unsigned int  txavail;                // Bytes avail (output)
  87.      unsigned char scnwid;                // Screen width, chars
  88.      unsigned char scnlen;                // Screen height, chars
  89.      unsigned int  bdmask;                // Baud rate mask
  90.      unsigned char filler[2];
  91. };
  92.  
  93. // Class //
  94.  
  95. class FosIo
  96.  
  97. // Description =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  98. //
  99. //    Bitmasks, values, paramater conversions, etc.
  100. //
  101. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  102. {
  103.    public:
  104.  
  105.    // baudrate bitmasks
  106.  
  107.    enum _baudmask
  108.    {
  109.       bmask  = 0x01e0, // mask
  110.       b19k   = 0x0000, //  19200
  111.       b38k   = 0x0020, //  38400
  112.       b300   = 0x0040, //    300
  113.       b600   = 0x0060, //    600
  114.       b1200  = 0x0080, //   1200
  115.       b2400  = 0x00a0, //   2400
  116.       b4800  = 0x00c0, //   4800
  117.       b9600  = 0x00e0, //   9600
  118.       b57k   = 0x0100, //  57600
  119.       b115k  = 0x0120  // 115200
  120.    };
  121.  
  122.    // databits bitmasks
  123.  
  124.    enum _datamask
  125.    {
  126.       dmask  = 0x0003, // mask
  127.       eight  = 0x0003, // 8
  128.       seven  = 0x0002, // 7
  129.       six    = 0x0001  // 6
  130.    };
  131.  
  132.    // parity bitmasks
  133.  
  134.    enum _parimask
  135.    {
  136.       pmask  = 0x0018, // mask
  137.       none   = 0x0000, // none
  138.       even   = 0x0018, // even
  139.       odd    = 0x0008, // odd
  140.       space  = 0x0010, // space
  141.       mark   = 0x0010  // mark
  142.    };
  143.  
  144.    // stop-bit bitmasks
  145.  
  146.    enum
  147.    {
  148.       smask  = 0x0004, // mask
  149.       one    = 0x0000, // 1
  150.       two    = 0x0004  // 2
  151.    };
  152.  
  153.    // some easier-to-use combined definitions
  154.  
  155.    enum
  156.    {
  157.       N81    = none|eight|one,
  158.       N82    = none|eight|two,
  159.       O71    = odd|seven|one,
  160.       E71    = even|seven|one,
  161.       N71    = none|seven|one,
  162.       O72    = odd|seven|two,
  163.       E72    = even|seven|two,
  164.       N72    = none|seven|two
  165.    };
  166.  
  167.    // flow control, etc. bitmasks
  168.  
  169.    enum
  170.    {
  171.       localxon  = 0x0001, // enable local xon/xoff
  172.       localcts  = 0x0002, // enable local cts/rts
  173.       remotexon = 0x0008, // enable remote xon/xoff
  174.       noflow    = 0x0000  // disable all flow control
  175.    };
  176.  
  177.    // line control and somesuch bitmasks
  178.  
  179.    enum
  180.    {
  181.       dtron     = 0x0001, // raise dtr
  182.       dtroff    = 0x0000, // lower dtr
  183.       brkon     = 0x0001, // send break
  184.       brkoff    = 0x0000  // stop sending break
  185.    };
  186.  
  187.    // status bitmasks
  188.  
  189.    enum
  190.    {
  191.       rxr       = 0x0100, // data in receive buffer
  192.       ovn       = 0x0200, // recive buffer overrun
  193.       txr       = 0x2000, // transmit buffer has room
  194.       txe       = 0x4000, // transmit buffer is empty
  195.       dcd       = 0x0080  // data carrier detect
  196.    };
  197.  
  198.    // constructor
  199.  
  200.    FosIo();                           // default
  201.  
  202.    // destructor
  203.  
  204.    ~FosIo();
  205.  
  206.    // conversion functions
  207.  
  208.    unsigned int _Cdecl stringToSetup(signed char * _s);
  209.    unsigned int _Cdecl valuesToSetup(unsigned long int _baudrate,
  210.                                      unsigned char _databits,
  211.                                      unsigned char _parity,
  212.                                      unsigned char _stopbits);
  213.    char * _Cdecl setupToString(unsigned int _setup, char * _s = 0);
  214.    void _Cdecl setupToValues(unsigned int _setup,
  215.                              unsigned long int & _baudrate,
  216.                              unsigned char & _databits,
  217.                              unsigned char & _parity,
  218.                              unsigned char & _stopbits);
  219.  
  220.    ////
  221.    //
  222.    // Protected Stuff
  223.    //
  224.    ////
  225.  
  226.    protected:
  227.  
  228.    unsigned int      commport,
  229.                      portmask;
  230.  
  231. };
  232. // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  233.  
  234. // Class //
  235.  
  236. class Fossil : public FosInfo, public TimInfo,
  237.                public FosData, public FosIo
  238.  
  239. // Description =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  240. //
  241. //    The FOSSIL class
  242. //
  243. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  244. {
  245.    ////
  246.    //
  247.    // Public Stuff
  248.    //
  249.    ////
  250.  
  251.    public:
  252.  
  253.    // constructors
  254.  
  255.    _Cdecl Fossil();
  256.    _Cdecl Fossil(unsigned int _port, unsigned int _cbrk = 0);
  257.    _Cdecl Fossil(unsigned int _port, unsigned char _mask, unsigned int _cbrk = 0);
  258.    _Cdecl Fossil(unsigned int _port, char * _initstr, unsigned int _cbrk = 0);
  259.    _Cdecl Fossil(unsigned int _port, unsigned long int _baud, unsigned char _data,
  260.                  unsigned char _pari, unsigned char _stop, unsigned int _cbrk = 0);
  261.  
  262.    // destructor
  263.  
  264.    _Cdecl ~Fossil();
  265.  
  266.    // initialisation member functions
  267.  
  268.    unsigned int _Cdecl open(unsigned int _port, unsigned char _mask,
  269.                             unsigned int _cbrk = 0);
  270.    unsigned int _Cdecl open(unsigned int _port, char * _initstr,
  271.                             unsigned int _cbrk = 0);
  272.    unsigned int _Cdecl open(unsigned int _port, unsigned long int _baud,
  273.                             unsigned char _data, unsigned char _pari,
  274.                             unsigned char _stop, unsigned int _cbrk = 0);
  275.  
  276.    // de-initialisation member function
  277.  
  278.    void _Cdecl close();
  279.  
  280.    // fossil manipulation...
  281.    // see notes in FOSSIL.CPP for more info.
  282.  
  283.    unsigned int _Cdecl set(unsigned char _mask);
  284.    unsigned int _Cdecl putW(unsigned char _c);
  285.    unsigned char _Cdecl getW();
  286.    unsigned int _Cdecl status();
  287.    unsigned char _Cdecl dtr(unsigned int _raise);
  288.    void _Cdecl flushOut();
  289.    void _Cdecl purgeOut();
  290.    void _Cdecl purgeIn();
  291.    unsigned int _Cdecl put(unsigned char _c);
  292.    unsigned int _Cdecl peek();
  293.    unsigned int _Cdecl peekKey();
  294.    unsigned int _Cdecl getKey();
  295.    void _Cdecl flow(unsigned char _mask);
  296.    unsigned int _Cdecl control(unsigned char _mask);
  297.    void _Cdecl gotoXY(unsigned char _row, unsigned char _col);
  298.    void _Cdecl whereXY(unsigned char & _row, unsigned char & _col);
  299.    void _Cdecl putANSI(unsigned char _c);
  300.    void _Cdecl watchdog(unsigned int _enable);
  301.    void _Cdecl putBIOS(unsigned char _c);
  302.    unsigned int _Cdecl timerChain(unsigned int _insert, void (far * _f)());
  303.    void _Cdecl reboot(unsigned int _warm);
  304.    unsigned int _Cdecl read(void far * _buffer, unsigned int _count);
  305.    unsigned int _Cdecl write(void far * _buffer, unsigned int _count);
  306.    void _Cdecl brk(unsigned int _start);
  307.    unsigned int _Cdecl installApi(unsigned char _code, void (far * _f)());
  308.    unsigned int _Cdecl removeApi(unsigned char _code, void (far * _f)());
  309.    unsigned int _Cdecl operator ! ();
  310.    unsigned int _Cdecl carrier();
  311.    unsigned int _Cdecl incoming();
  312.    unsigned int _Cdecl mode();
  313.    void _Cdecl info();
  314.  
  315.    ////
  316.    //
  317.    // Protected Stuff
  318.    //
  319.    ////
  320.  
  321.    protected:
  322.  
  323.    unsigned int foserr; // for internal error flags
  324.  
  325.    ////
  326.    //
  327.    // Private Stuff
  328.    //
  329.    ////
  330.  
  331.    private:
  332.  
  333.    unsigned char ctlcnt,        // ^C counter if requested
  334.                  initialised;   // non zero if FOSSIL is on
  335.  
  336.    // common initialisation subfunction
  337.  
  338.    unsigned int _Cdecl _initialise(unsigned char far * _countc = NULL);
  339.  
  340.    // common de-initialisation subfunction
  341.  
  342.    void _Cdecl _deInitialise();
  343.  
  344.    // low-level tick checker
  345.  
  346.    void _Cdecl _getTicks(TimInfo & T);
  347.  
  348.    // get fossil driver info subfunction
  349.  
  350.    unsigned int _Cdecl _info(FosData & _D);
  351. };
  352. // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  353.  
  354. #endif
  355.